module("LoginHomeUI", package.seeall)

function create(scene)
	local self = ccs.GUIReader:getInstance():widgetFromJsonFile("res/UI/LoginUI/LoginHomeUI.ExportJson")
	self._loginScene = scene
	init(self)
	return self
end

function onButtonAccountClick(self)
	LoginScene.showUILayer(self._loginScene, AccountUI)
end

function onButtonServerClick(self)
	LoginScene.showUILayer(self._loginScene, ServerSelectUI)
end

function onButtonEnterClick(self)
	SceneManager.switchToScene(HomeScene.create())
end

function init(self)
	self._button_enter = self:getChildByName("Button_Start")
	self._button_server = self:getChildByName("Button_Server")
	self._button_account = self:getChildByName("Button_Account")
	self._label_account = self._button_account:getChildByName("Label_Name")
	self._label_server = self._button_server:getChildByName("Label_Name")


	self._label_account:setText(AccountUI.getAccountName())
	self._label_server:setText(LoginScene.server.caption)

	self._button_enter:addTouchEventListener(
		function(sender, eventType)
			if (eventType == ccui.TouchEventType.ended) then
				onButtonEnterClick(self)
			end
		end)

	self._button_server:addTouchEventListener(
		function(sender, eventType)
			if (eventType == ccui.TouchEventType.ended) then
				onButtonServerClick(self)
			end
		end
		)

	self._button_account:addTouchEventListener(
		function(sender, eventType)
			if (eventType == ccui.TouchEventType.ended) then
				onButtonAccountClick(self)
			end
		end
		)
end